//////////////////////////////////////////////////////////////////////
////                                                              ////
////  IOPeripherals.v                                            ////
////                                                              ////
////                                                              ////
////  This file is part of the core Pico E12 firmware             ////
////                                                              ////
//// Copyright (C) 2005, Picocomputing, Inc.                      ////
//// http://www.picocomputing.com/                                ////
////                                                              ////
////////////////////////////////////////////////////////////////////JF

//This is where user IO peripherals attach


`timescale 10ns / 1ns
`include "PicoDefines.v"


module IOPeripherals
   (input IORead,				                          //IO Read from Card
    input IOWrite,                                        //IO Write to Card
    input [`PCMCIA_ADR_LINES-1:0]IOAddress,               //IO Address Bus
    input [15:0]DataIn,                                   //Data In from Host
    output [15:0]DataOut,                                 //Data Out to Host

    output JTAG_LOOPBACK_TCK,                             //JTAG Signals
    output JTAG_LOOPBACK_TDI,
    input JTAG_LOOPBACK_TDO,
    output JTAG_LOOPBACK_TMS,

    input  FLASH_BUSY,                                    //Status and Reset Signals
    output FLASH_RESET,
    input  DcmsLocked,
    input  BackplaneDetected);

wire [15:0]JTAGDataOut;
wire [15:0]StatusAndResetDataOut;

//------------------JTAG Parallel Port Emulation---------------------
JTAGEmulator JTAGEmulator(.enable(~IOAddress[2]), .addr(IOAddress[1:0]), .din(DataIn[7:0]), .dout(JTAGDataOut[15:0]), .read(IORead), .write(IOWrite),
                          .tck(JTAG_LOOPBACK_TCK), .tdi(JTAG_LOOPBACK_TDI), .tdo(JTAG_LOOPBACK_TDO), .tms(JTAG_LOOPBACK_TMS));


//---------------------Status and Reset Unit-------------------------
StatusAndReset StatusAndReset(
    .IORead(IORead), .IOWrite(IOWrite), .IOAddress(IOAddress[`PCMCIA_ADR_LINES-1:1]), .DataIn(DataIn[15:0]), .DataOut(StatusAndResetDataOut[15:0]), 
    .FLASH_BUSY(FLASH_BUSY), .FLASH_RESET(FLASH_RESET), .DcmsLocked(DcmsLocked), .BackplaneDetected(BackplaneDetected));

assign DataOut[15:0] = (JTAGDataOut[15:0] | StatusAndResetDataOut[15:0]);

endmodule